import { defineConfig, loadEnv } from "vite";
import vue from "@vitejs/plugin-vue";
import { join } from "path";

// const serverUrl  =   "http://www.score.com"   ;
// const serverUrl  =    "http://score.0898yzzx.com" ;


export default defineConfig(({ mode }) => {
  const serverUrl =loadEnv(mode, process.cwd()).VITE_HOST;
  console.log('当前后端地址：' + serverUrl);
  // https://vitejs.dev/config/
  return {
    plugins: [vue()],
    //配置src目录别名
    resolve: {
      alias: {
        "@": join(__dirname, "src"),
      },
    },
    //配置代理跨域
    server: {
      proxy: {
        "/api": {
          target: serverUrl,
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/api/, "/api"),
        },
      },
    },
  };
});
